package com.cn.demo5;

import java.io.File;

/**
 * 1.获取类路径根目录
 * 2.获取当前类所在的包路径
 */
public class DemoPath {
    public void printClassPath() {
        // 获取类路径根目录
        File f = new File(this.getClass().getResource("/").getPath());
        System.out.println("类路径根目录为: " + f.getAbsolutePath());

        // 获取当前类所在的包路径
        File current = new File(this.getClass().getResource("").getPath());
        System.out.println("当前类所在路径为: " + current.getAbsolutePath());
    }

    public static void main(String[] args) {
        DemoPath demo = new DemoPath();
        demo.printClassPath();
    }
}

